<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for SRI require-sri-for CSP directive</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1265318">Mozilla Bug 1265318</a><br>
<iframe style="width:200px;height:200px;" id="test_frame"></iframe><br>
</body>
<script type="application/javascript">
  var finished = 0;
  SpecialPowers.setBoolPref("security.csp.experimentalEnabled", true);
  SimpleTest.waitForExplicitFinish();
  function handler(event) {
    console.log(event);
    switch (event.data) {
      case 'finish':
        // need finish message from iframe_require-sri-for_main onload event and
        // from iframe_require-sri-for_no_csp, which spawns a Worker
        var importText = frame.contentDocument.getElementById('text-for-import-test');
        var importColor = frame.contentWindow.getComputedStyle(importText, null).getPropertyValue('color');
        ok(importColor == 'rgb(0, 0, 255)', "The import should not work without integrity. The text is now red, but should not.");
        removeEventListener('message', handler);
        SimpleTest.finish();
        break;
      default:
        ok(false, 'Something is wrong here');
        break;
    }
  }
  addEventListener("message", handler);
  // This frame has a CSP that requires SRI
  var frame = document.getElementById("test_frame");
  frame.src = "iframe_csp_directive_style_imports.html";
</script>
</html>
